<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>滨江后勤外卖抢单</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/assets/base/restaurant/courier/css/style.css">
</head>
<body>
<div class="wraper">
    <header class="text-center font-white font-16">
        <div class="back iconfont icon-back"></div>
        订单广场
    </header>
    <div class="tab text-center">
        <div class="tab-list actived" data-id="1">
            <div class="min_tab">待抢单<span class="font-12">（10）</span></div>
        </div>
        <div class="tab-list" data-id="2">
            <div class="min_tab">待配送<span class="font-12">（10）</span></div>
        </div>
        <div class="tab-list" data-id="3">
            <div class="min_tab">已送达</div>
        </div>
    </div>

    <!--待抢单-->

    <div class="contain" id="vie">

        <div class="hide">
            <div class="none">
                <img src="images/none.png" alt="">
            </div>
            <p class="text-center font-gray">暂无订单</p>
        </div>

    </div>

    <!--待配送-->

    <div class="contain hide" id="delivery">

        <div class="hide">
            <div class="none">
                <img src="images/none.png" alt="">
            </div>
            <p class="text-center font-gray">暂无订单</p>
        </div>
    </div>

    <!--已送达-->

    <div class="contain hide" id="over">

        <div class="hide">
            <div class="none">
                <img src="images/none.png" alt="">
            </div>
            <p class="text-center font-gray">暂无订单</p>
        </div>

    </div>
</div>
</body>
<script src="/assets/base/restaurant/courier/js/jquery-2.1.0.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<include file="share_header"/><!--wx.config配置-->
<script>
    $(function () {

        ajaxData(1);

        var height = $(window).height();
        var header_height = $('header').outerHeight(true);
        var tab_height = $('.tab').outerHeight(true);
        $('.contain').css('height', height - header_height - tab_height);

        $('.icon-dianhua').click(function () {
            var number = $(this).data('number');
            $(this).attr("href", 'tel:' + number);
        });

        $('.tab').on('click', '.tab-list', function () {
            var idx = $(this).index();
            $('.contain').eq(idx).removeClass('hide').siblings('.contain').addClass('hide');
            $(this).addClass('actived').siblings('.tab-list').removeClass('actived');

            var id = $(this).data('id');
            ajaxData(id);
        })

        $(function () {
            var height = $(window).height() - $('.header').outerHeight() - 15;
            $('.contain').css('height', height);
        })

        var page = 0;
        //异步加载订单信息
        $(window).scroll(function (event) {
            page += 2;
            if ($(document).scrollTop() + $(window).height() > $(document).height() - 10) {
                $('.nav_list').each(function () {
                    if ($(this).hasClass('actived')) {
                        var id = $(this).data('id');
                        ajaxData(id, page);
                    }
                })

            }
        });

        /*ajax获取首页内容*/
        function ajaxData(id, page) {
            if (!page) {
                page = 0;
            }
            $.ajax({
                url: '/base/restaurant/ajaxCourierData/res_id/{BEESCRM:$res_id}',
                type: 'POST',
                data: {'status': id},
                dataType: 'html',
                success: function (data) {
                    if (!data.status && data != '') {
                        if (id == 1) {
                            if (!page) {
                                $('.info').remove();
                            }
                            $("#vie").prepend(data);
                        } else if (id == 2) {
                            if (!page) {
                                $('.info').remove();
                            }
                            $("#delivery").prepend(data);
                        } else if (id == 3) {
                            if (!page) {
                                $('.info').remove();
                            }
                            $("#over").prepend(data);
                        }
                    } else if (data.status == 'F') {
                        alert(data.message);
                    }
                }
            });
        }

        $(document).on('click', '#vie_list', function () {
            var text = $(this).text();
            text = text.replace(/\s+/g, "");
            var _this = $(this);
            var data = {};
            data.order_id = $(this).data('order_id');
            data.window_id = $(this).data('window_id');

            if (text == '抢单') {

                $.ajax({
                    url: '/base/restaurant/ajaxVieList/res_id/{BEESCRM:$res_id}',
                    type: 'POST',
                    data: data,
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 'S') {
                            alert(res.message);
                            _this.parents('.info').remove();
                            return false;
                        } else {
                            alert(res.message);
                            return false;
                        }
                    }
                });
            }

            if (text == '送达') {
                //调微信扫一扫接口
                wx.scanQRCode({
                    needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                    scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                    success: function (res) {
                        var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    }
                });
            }

        })
    });

</script>
</html>